package com.artist.controller;

import com.artist.entity.TbDepartment;
import com.artist.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "角色管理")
@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    @ApiOperation(value = "角色列表")
    @GetMapping("/department")
    @ResponseBody
    public List<TbDepartment> getAll(Model model){
        List<TbDepartment> departments= departmentService.selectAll();
        return departments;
    }
    @ApiOperation(value = "新增角色")
    @PostMapping("/department")
    public void insertDepartment(@RequestBody TbDepartment tbDepartment){
        departmentService.saveDepartment(tbDepartment);
    }
    @ApiOperation(value = "编辑角色")
    @PutMapping("/department/{did}")
    @ResponseBody
    public String updateDepartment(@RequestBody TbDepartment department){
        departmentService.updateByPrimaryKeySelective(department);
        System.out.println(department);
        return "editdepartment";
    }
    @ApiOperation(value = "查询角色")
    @GetMapping("/department/{did}")
    @ResponseBody
    private TbDepartment selectDepartmentByPrimaryKey(@PathVariable Integer  did){
      TbDepartment department=  departmentService.selectDepartmentById(did);
        return  department;
    }
    @ApiOperation(value = "删除角色")
    @DeleteMapping("/department/{did}")
    private String deleteDepartment(@PathVariable Integer did){
        departmentService.deleteDepartment(did);
        return "department";
    }

}
